#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@Author  :   JingV
@Version :   1.0
@Contact :   None
@License :   None
@Desc    :   None
'''


class Solution(object):
    def strStr(self, haystack, needle):
        len_haystack, len_needle = len(haystack), len(needle)
        if len_needle == 0:
            return 0
        if len_needle > len_haystack:
            return -1
        for i in range(len_haystack - len_needle + 1):
            if haystack[i: i+len_needle] == needle:
                return i
        return -1


def main():
    solution = Solution()
    tests = [
        ("mississippi", "pi"),
        ('1', '1'),
        ('hello', 'll'),
        ('aaaaa', 'bba')
    ]
    for haystack, needle in tests:
        print(solution.strStr(haystack, needle))


if __name__ == "__main__":
    main()
